package service.impl;

import entity.UserEntity;
import dao.UserDao;
import dao.impl.UserDaoImpl;
import service.UserService;
import util.PasswordUtil;
import util.UUIDUtil;

public class UserServiceImpl implements UserService {
    private final UserDao userDao = new UserDaoImpl();
    @Override
    public boolean getUserInfo(String userName,String password) {
            UserEntity user = userDao.findByUsername(userName);
            return user != null && PasswordUtil.checkPassword(password, user.getPassword());
    }

    @Override
    public boolean registered(String userName, String password) {
            if (userDao.findByUsername(userName) != null) {
                return false; // 用户名已存在
            }
            UserEntity user = new UserEntity();
            user.setId(UUIDUtil.getUUID());
            user.setUsername(userName);
            user.setPassword(PasswordUtil.hashPassword(password));
            return userDao.insert(user) == 1;
    }
}
